<template>
    <div>
        <h1>医生信息录入</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>姓名</td>
                    <td><input type="text" v-model="data.Dname"></td>
                </tr>
                <tr>
                    <td>头像</td>
                    <td>
                        <input type="file" @change="shangc">
                        <img :src="'https://localhost:7292/'+data.Img" style="width: 60px;height: 60px;">
                    </td>
                </tr>
                <tr>
                    <td>科室</td>
                    <td>
                        <select v-model="data.Mid">
                            <option value="0">科室</option>
                            <option v-for="d in xiala" :value="d.DMid">{{ d.DMname }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>创建日期</td>
                    <td><input type="date" v-model="data.Dtimes"></td>
                </tr>
                <tr>
                    
                    <td><input type="button" value="添加" class="btn btn-success" @click="tianj()"></td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';

onMounted(() => {
   KSXL(); 
});
const data = ref({

  "Did": 0,
  "Dname": "",
  "Img": "",
  "Mid": 0,
  "Dtimes": "2025-05-19T04:44:55.896Z"

})

const tianj = ()=>{
    if(data.value.Dname=="")
    {
        alert("姓名不能为空");
        return;
    }
    axios.post("https://localhost:7292/api/Doctor/AddYS",data.value).then(res=>{
        if(res.data==1)
        {
            alert("添加成功");
            location.href="/ShowYS";
        }
        else
        {
            alert("添加失败");
        }
    })
}
///////上传图片////////////
const shangc=(a:any)=>{
    var f = a.target.files[0];
    var fd = new FormData;
    fd.append("file",f)
    if(f.size>1024*1024*2)
    {
        alert("文件大小不能超过2MB!");
        return;
    }

    axios.post("https://localhost:7292/api/Image/tupian",fd).then(res=>{
        data.value.Img=res.data
    })
}
///////科室下拉//////////////
const xiala = ref([
    {
    "DMid": 0,
    "DMname": "",
  }
])
const KSXL = ()=>{
    axios.get("https://localhost:7292/api/Deparment/daoc").then(res=>{
        xiala.value=res.data
    })
}
</script>

<style scoped>

</style>